import React, { useEffect } from 'react';
import { Card, Button, Typography, Space } from 'antd';
import { WechatOutlined } from '@ant-design/icons';
import { history } from 'umi';
import { getLoginUrl } from '@/services/auth';
import styles from './index.less';

const { Title, Paragraph } = Typography;

const LoginPage: React.FC = () => {
  const handleLogin = async () => {
    try {
      const { data } = await getLoginUrl();
      window.location.href = data.url;
    } catch (error) {
      console.error('获取登录URL失败:', error);
    }
  };

  // 检查URL中是否有token参数
  useEffect(() => {
    const params = new URLSearchParams(window.location.search);
    const token = params.get('token');
    if (token) {
      localStorage.setItem('token', token);
      history.push('/');
    }
  }, []);

  return (
    <div className={styles.container}>
      <Card className={styles.card}>
        <Space direction="vertical" align="center" style={{ width: '100%' }}>
          <Title level={2}>流量运营与销售沟通平台</Title>
          <Paragraph>使用企业微信账号登录</Paragraph>
          <Button
            type="primary"
            icon={<WechatOutlined />}
            size="large"
            onClick={handleLogin}
            className={styles.loginButton}
          >
            企业微信登录
          </Button>
        </Space>
      </Card>
    </div>
  );
};

export default LoginPage; 